<!DOCTYPE html>
<html lang="zh-CN">
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>UserManager</title>
    <link rel="shortcut icon" href="../static/admin/image/favicon.ico"/>
    <link href="../static/admin/css/signin.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="../static/admin/css/bootstrap.min.css"/>
</head>


<div class="container">


    <div class="hvcenter" id="maintext">

        <form class="form-signin" method="post" id='mainform'>
            <h3 class="form-signin-heading" style="color:#FFFFFF" id="title">Please signin</h3>
            <input style="opacity:0.8;" name="inputEmail" type="text" id="username" class="form-control"
                   placeholder="Username" required autofocus>
            <input style="opacity:0.8;" name="inputPassword" type="password" id="password" class="form-control"
                   placeholder="Password" required>
        </form>
        <button class="btn btn-lg btn-outline-primary btn-block" id="loginbtn">生成邀请码</button>
        <div id="errtip"></div>

    </div>


    <script src="../static/admin/js/jssha256.js"></script>
    <script src="../static/admin/js/jquery-3.2.1.min.js"></script>
    <script src="../static/admin/js/popper.min.js"></script>
    <script src="../static/admin/js/bootstrap.min.js"></script>
    <script src="../static/admin/js/jquery.backstretch.min.js"></script>
    <script src="../static/admin/js/bigimage.js"></script>
</div> <!-- /container -->

</body>

<script>
    $("#loginbtn").click(function () {
        var pwd = $("#password").val();
        var pwdsha = SHA256_hash(pwd);
        var username = $("#username").val();
        $.post("/genincode", {"username": username, "password": pwdsha}, function (data) {
            if (data == 'pwdfail') {
                $("#errtip").html('<div class="alert alert-danger" role="alert"  align="center">密码错误</div>');
            }
            else if (data == 'userfail') {
                $("#errtip").html('<div class="alert alert-danger" role="alert"  align="center">用户不存在</div>');
            }
            else if (data == 'authorityfail') {
                $("#errtip").html('<div class="alert alert-danger" role="alert"  align="center">权限不足</div>');
            } else {
                $("#errtip").html('<div class="alert alert-success" role="alert"  align="center">请复制上方的邀请码</div>');
                $("#maintext").prepend('<h1 class="form-signin-heading" style="color:#FFFFFF">'+data+'</h1>');
            }
        });
    });
</script>

</html>
